package br.ucb.sigplan.action.impl;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.ucb.sigplan.action.Action;
import br.ucb.sigplan.beans.Login;
import br.ucb.sigplan.beans.Professor;
import br.ucb.sigplan.crud.ProfessorCrud;

public class AbrirAlteraProfessorAction implements Action {

	@Override
	public String execute(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		Professor professor;
		if (req.getParameter("idProfessor") != null) {
			Integer idProfessor = new Integer(req.getParameter("idProfessor"));
			professor = ProfessorCrud.findById(idProfessor);
		}else{
			Login login = (Login) req.getSession().getAttribute("login");
			professor = ProfessorCrud.findByEmail(login.getEmail());
		}
		req.setAttribute("professor", professor);
		req.getSession().setAttribute("professor", professor);
		if (req.getParameter("acao").equalsIgnoreCase("alterarProfessor")) {
			return "/jsp/diretor/professor/dirAlteraProfessor.jsp";
		}
		else {
			return "/jsp/alteraDadosPessoais.jsp";
		}
		
	}

}
